/*
* tmf_measure_test.c
*/

#include "tmf_measure.h"
#include "intf_tmf_measure.h"

void  prnt_tmpr(float tmpr, time_t time)
{
	printf("time: %d, temperature %f\n", time, tmpr);
}

int get_tmpr(int n)
{
	int ret, count = 0;
	float tmpr;
	time_t tm;

	while(count ++ < n) {
		if((ret = tmf_msr_get_tmpr(&tmpr, &tm)) < 0) {
			printf("%d: tmf_msr_get_tmpr failed\n", ret);
			return -1;
		} else {
			printf("time: %d, temperature %f\n", tm, tmpr);
		}
		sleep(1);
	}
	return 0;
}
int main(int argc, char * argv[])
{
	int ret;
	enum TMF_MSR_MODE mode;
	
	if((ret = tmf_msr_init(argc, argv)) < 0) {
		printf("%d: tmf_msr_init failed\n", ret);
		exit(0);
	}
	mode = TMF_MEASURE_MODE_PASSIVE;
	if((ret = tmf_msr_set_mode(mode, 0)) < 0) {
		printf("%d: tmf_msr_set_mode failed\n", ret);
		exit(0);
	}
	get_tmpr(10);
	mode = TMF_MEASURE_MODE_AUTO;
	if((ret = tmf_msr_set_mode(mode, 1)) < 0) {
		printf("%d: tmf_msr_set_mode failed\n", ret);
		exit(0);
	}
	tmf_msr_set_notify_callback(prnt_tmpr);
	sleep(30);
		mode = TMF_MEASURE_MODE_PASSIVE;
	if((ret = tmf_msr_set_mode(mode, 0)) < 0) {
		printf("%d: tmf_msr_set_mode failed\n", ret);
		exit(0);
	}
	get_tmpr(10);
	tmf_msr_deinit();
	return 0;
}

